package cn.edu.zust.se.shop.controller;

import cn.edu.zust.se.shop.dto.ProductDto;
import cn.edu.zust.se.shop.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("products")
public class ProductController {
    @Autowired
    ProductService productService;
    @GetMapping("/{id}")
    public ProductDto getProductById(@PathVariable("id") Integer id){
        return productService.getProductById(id);
    }

    @GetMapping("")
    public List<ProductDto> getAllProducts(){
        return productService.getAll();
    }
    @GetMapping("/{productId}/sail")
    public ProductDto sailOut(@PathVariable Integer productId,int num){
        return productService.sailOut(productId,num);
    }
}
